var qcloud = require('../vendor/sdk/index');
var config = require('../config');
const app = getApp();

export default {
  syncReadedVoiceMessage: () => {
    if (app.globalData.userInfo && app.globalData.userInfo.role == -1) {
      console.log('游客不同步记录已读语音记录');
      return;
    }
    let obj = wx.getStorageSync('readedVoiceMessage');
    if (obj && obj.programId && obj.userId && obj.uuid) {
      // 持久化已读语音记录
      qcloud.request({
        url: config.service.updateReadVoiceMessageUrl,
        data: {
          programId: obj.programId,
          userId: obj.userId,
          uuidStr: obj.uuid,
        },
        success: res => {
          console.log('已播放语音持久化成功');
        }
      });
      wx.removeStorageSync('readedVoiceMessage');
    }
  },
  categoryClickCountIncrease(categoryId) {
    if (!categoryId) {
      return;
    }
    qcloud.request({
      url: config.service.updateCategoryClickCountUrl,
      data: {
        categoryId,
      },
      success: res => {
        console.log('分类点击次数增加成功');
      }
    });
  },
  miniProgramClickCountIncrease(miniProgramId) {
    if (!miniProgramId) {
      return;
    }
    qcloud.request({
      url: config.service.updateMiniProgramClickCountUrl,
      data: {
        miniProgramId,
      },
      success: res => {
        console.log('小程序点击次数增加成功');
      }
    });
  },
  urlCheck: (url) => {
    if (url.indexOf('//') == -1) {
      return false;
    }
    if (url.indexOf('mp.weixin.qq.com') != -1) {
      return true;
    }
    return false;
    // console.log('链接地址检测', url);
    // let regex = "^((https|http|ftp|rtsp|mms)?://) ?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.[a-z]{2,6})(:[0-9]{1,4})?((/?)|(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$$";
    // let arr = url.split("//");
    // let protocol = arr[0];
    // let domain = arr[1].split('/')[0];
    // url = protocol + '//' + domain;
    // if (url.match(regex)) {
    //   console.log('是链接地址');
    //   return true;
    // }
    // return false;
  },
  emoji: [
    { char: '😀' },
    { char: '😂' },
    { char: '😊' },
    { char: '😋' },
    { char: '😉' },
    { char: '😎' },
    { char: '🙁' },
    { char: '😭' },
    { char: '😡' },
    { char: '😷' },
    { char: '😙' },
    { char: '😏' },
    { char: '😵' },
    { char: '😬' },
    { char: '😅' },
    { char: '😍' },
    { char: '😘' },
    { char: '😴' },
    { char: '🙄' },
    { char: '😜' },
    { char: '😱' },
    { char: '😳' },
    { char: '😆' },
    { char: '🤔' },
    { char: '😒' },
    { char: '😌' },
    { char: '😏' },
    { char: '😨' },
    { char: '🙃' },
    { char: '😖' },
    { char: '😣' },
    { char: '😓' },
    { char: '🤧' },
    { char: '🤤' },
    { char: '😪' },
    { char: '👌' },
    { char: '👍' },
    { char: '✌️' },
    { char: '🤝' },
    { char: '👏' },
    { char: '👎' },
    { char: '💪' },
    { char: '✊' },
    { char: '👇' },
    { char: '☝️' },
    { char: '🙌' },
    { char: '👋' },
    { char: '🤝' },
    { char: '👈' },
    { char: '👉' },
    { char: '✍️' },
    { char: '🤙' },
    { char: '🙏' },
    { char: '😿' },
    { char: '😺' },
    { char: '😾' },
    { char: '🙀' },
    { char: '😻' },
    { char: '💩' },
    { char: '💀' },
    { char: '❤️' },
    { char: '💄' },
    { char: '💋' },
    { char: '😈' },
    { char: '👿' },
    { char: '☂️' },
    { char: '👑' },
    { char: '🔥' },
    { char: '🎭' },
    { char: '🎨' },
    { char: '🎬' },
    { char: '🎻' },
    { char: '☃️' },
    { char: '💍' },
    { char: '👻' },
    { char: '🚶' },
    { char: '🏃' },
    { char: '💃' },
    { char: '🕺' },
    { char: '🕴️' },
  ],
}
